﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Text;
using System.Net;
using System.IO;

public partial class DangNhap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnHuy_Click(object sender, EventArgs e)
    {
        txtMatKhau.Text = "";
        txtTenTruyCap.Text = "";
    }
    protected void btnDangNhap_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        OleDbConnection connect = new OleDbConnection();
        string strChuoiKetNoi = "";
        strChuoiKetNoi = "provider = microsoft.jet.oledb.4.0;Data Source=" + Server.MapPath("App_Data\\MSG.mdb");
        connect.ConnectionString = strChuoiKetNoi;
        connect.Open();

        string sql = "select * from NguoiDung where TenTruyCap = '" + txtTenTruyCap.Text + "' and MatKhau = '" + txtMatKhau.Text + "'";
        OleDbDataAdapter da = new OleDbDataAdapter(sql, connect);

        da.Fill(ds, "admin");

        if (ds.Tables["admin"].Rows.Count > 0)
        {            
            Session["TenDangNhap"] = txtTenTruyCap.Text.ToString().ToLower();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = connect;
            comm.Parameters.Add("a1", txtTenTruyCap.Text);
            string strChuoiCapNhat;
            strChuoiCapNhat = "update NguoiDung set Status=yes where TenTruyCap=a1";
            comm.CommandText = strChuoiCapNhat;
            try
            {
                comm.ExecuteNonQuery();
                connect.Close();

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            Response.Redirect("NguoiDung.aspx");
        }
        else
        {
            lblKetQua.Text = "Sai Tên Đăng Nhập Hoặc Mật Khẩu!!!";
        }
    }
}
